package com.cdtye.shuoh.config.gb28181.sip.event;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import javax.sip.ResponseEvent;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
@ConditionalOnProperty(value = "sip.enabled", havingValue = "true")
public class SipSubscribe {

    private Map<String, Event> errorSubscribes = new ConcurrentHashMap<>();

    private Map<String, Event> okSubscribes = new ConcurrentHashMap<>();

    public interface Event {
        void response(ResponseEvent event);
    }

    public void addErrorSubscribe(String key, Event event) {
        errorSubscribes.put(key, event);
    }

    public void addOkSubscribe(String key, Event event) {
        okSubscribes.put(key, event);
    }

    public Event getErrorSubscribe(String key) {
        return errorSubscribes.get(key);
    }

    public Event getOkSubscribe(String key) {
        return okSubscribes.get(key);
    }

    public int getErrorSubscribesSize(){
        return errorSubscribes.size();
    }
    public int getOkSubscribesSize(){
        return okSubscribes.size();
    }
}
